package main

import (
	"fmt"
	"os"
	"strings"
)

func main() {
	var path string = "C:\\Users\\18010\\Pictures\\bg"
	f, err := os.OpenFile(path, os.O_RDONLY, os.ModeDir)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer f.Close()

	// 读取目录
	info, err := f.Readdir(-1)
	if err != nil {
		fmt.Println(err)
		return
	}
	// 遍历返回的切片
	for _, fileInfo := range info {
		if !fileInfo.IsDir() {
			// 判断后缀
			if strings.HasSuffix(fileInfo.Name(), ".jpg") {
				fmt.Println(fileInfo.Name())
			}
		}
	}
}
